#include "resource.h"
#include "buffer.h"
#include <string.h>
int TestGetResource( const char * canfind );

int main()
{
	string texttypes [] = { "html", "css" };
	TextResourceChecker::Config( texttypes, 2 );
	TestGetResource( "index.html" );
	TestGetResource( "fuck" );
	return 0;
}


int TestGetResource( const char * canfind)
{
	char dirpath[] = "/home/kuncai/workspace/xpie/src/";
	
	Resource::Config(dirpath);

	ResourceItem* ptResourceItem = Resource::GetResource(canfind);
	
	if ( ptResourceItem != NULL )
	{
		Buffer * ptBufferIndex = ptResourceItem->GetBuffer();
		if (ptBufferIndex != NULL)
		{
			printf("the type is %s\n", ptResourceItem->GetType().c_str() );
			printf("the index html length is : %d and the text:\n", ptBufferIndex->GetLimit() );
			string str = ptBufferIndex->GetByteBuffer();
			printf("%s\n",ptBufferIndex->GetByteBuffer());
			printf("%s\n",str.c_str() );
			char dest[256] = {0};
			snprintf( dest, 256, "%s%s%s", dirpath, canfind, "2" );	
			printf( "copy  %s\n", dest );
			FILE * fp = fopen( dest, "w+" );
			fwrite( ptBufferIndex->GetByteBuffer(), 1, ptBufferIndex->GetLimit(), fp );
			fclose(fp);
		}
		else
		{
			printf("ptBufferIndex is NULL\n");
		}
	}
	return 0;
}

